import { local } from "../utils/storage";

export const AxiosRequestHeader = (config) => {
  config['baseURL'] = '/api'
  config.headers['timeout'] = 5e3
  config.headers['Access-Control-Allow-Origin'] = '*'
  config.headers['X-Requested-With'] = 'XMLHttpRequest'
  config.headers['Content-Type'] = 'application/json; charset=UTF-8'
  if (config.method === 'put') {
    config.headers['Context-Type'] = 'x-www-form-urlencoded; charset=UTF-8'
  }
  return config;
}

export const AxiosRequestAuthorization = (config) => {
  // TODO AXIOS 请求头追加 JWT-TOKEN
  const token = local.get('ADMIN.TOKEN') || ''
  if (token) {
    config.headers['Authorization'] = token;
  }
  return config;
}
